import axios from 'axios'
import {Message} from 'element-ui'

//设置默认请求头
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'

//创建axios实例
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 30000
})

//request拦截器
service.interceptors.request.use(config => {
  //处理请求前的事，例如增加token等
  return config;
}, error => {
  Promise.reject(error)
})

service.interceptors.response.use(res => {
  const code = res.data.code;
  // if(code == '0000'){
  //
  // }
  //TODO 暂时先直接返回数据
  return Promise.resolve(res.data)

}, error => {
  Message({
    message: error.message,
    type: 'error',
    duration: 5 * 1000
  })
  return Promise.reject(error)
})

export default service



